package com.ytc.basic.controller;

import com.ytc.basic.domain.Dictionary;
import com.ytc.commons.model.vo.DictionaryVo;
import com.ytc.commons.model.vo.ResponseResult;
import com.ytc.commons.utils.BeanHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ytc.basic.service.DictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 数据字典前端控制器
 * </p>
 *
 * @author
 */
@Slf4j
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {

    @Autowired
    private DictionaryService  dictionaryService;

    /*
    * 查询字典数据
    * GET
    * 相应数据ResponseResult<List<DictionaryVo>>
    * */
    @GetMapping
    public ResponseResult<List<DictionaryVo>> findAll(){
        //1.调用service查询所有
        List<Dictionary> list = dictionaryService.list();
        //2.转化
        List<DictionaryVo> voList = BeanHelper.copyWithCollection(list,DictionaryVo.class);
        //3.返回
        return ResponseResult.okResult(voList);

    }
    /*
     * 查询字典数据
     * GET:/{code}
     * 相应数据ResponseResult<DictionaryVo>
     * */
    @GetMapping("/{code}")
    public ResponseResult<DictionaryVo> findByCode(@PathVariable("code") String code){
        return dictionaryService.findByCode(code);
    }
}
